var io = require('socket.io')();
var logger = require('log4js').getLogger();
var net = require("net");
var server = net.createServer();


io.on('connection', function (client) {
    logger.info("client connect");
    var address = client.handshake.address;
    logger.info('New connection from ' + address);
    var command = "uname -a";
    client.on('console', function (data) {
        logger.info("获取到构建结果");
        logger.info(data);
        //暂时认为构建成功了，这个获取构建结果方式未定
    });
    client.on('agenterror', function (err) {
        logger.error("构建出错");
        logger.error(err);
    });
    client.on('disconnect', function () {
        logger.info('disconnect')
    });
    client.on('error', function (err) {
        logger.info(err)
    });
    client.on('init',function(data){
        logger.info("接入一个socket客户端");
        logger.info(data);
        client._Id = data.containerId;
        client.count = 0;

        var command = "uname -a";
        client.emit('exec', {command:command, cwd:"/app"});
    });
    client.emit('exec', {command: command, cwd: "/app"});
});


logger.info('echo server bound at port1 - ' + 8036);
io.listen(8036);